package com.timi_licai.timi_licai_account.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.timi_licai.timi_licai_account.R;
import com.timi_licai.timi_licai_account.listener.CategoryCustomInterface;
import com.timi_licai.timi_licai_account.listener.CategoryUpdateInterface;

/**
 * 点击添加信息页面的相机图标 弹出的dialog
 */
public class UpdateCategoryCustomDialog extends Dialog implements View.OnClickListener {
    private CategoryUpdateInterface categoryUpdateInterface;
    private EditText editDialogEdit;
    private ImageView imgDialogIcon;
    private String editTex;
    private int position;

    public UpdateCategoryCustomDialog(Context context, int theme,
                                      CategoryUpdateInterface categoryUpdateInterface) {
        super(context, theme);
        this.categoryUpdateInterface = categoryUpdateInterface;
    }

    public UpdateCategoryCustomDialog(Context context, int theme,
                                      CategoryUpdateInterface categoryUpdateInterface, String editText, int position) {
        super(context, theme);
        this.categoryUpdateInterface = categoryUpdateInterface;
        this.editTex = editText;
        this.position = position;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_update_category_custom);
        TextView txtDialogCancel = (TextView) findViewById(R.id.dialog_category_update_cancel);
        TextView txtDialogEnsure = (TextView) findViewById(R.id.dialog_category_update_ensure);
        imgDialogIcon = (ImageView) findViewById(R.id.dialog_category_custom_image);
        editDialogEdit = (EditText) findViewById(R.id.dialog_category_update_edit);
        editDialogEdit.setText(editTex);
        txtDialogCancel.setOnClickListener(this);
        txtDialogEnsure.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (categoryUpdateInterface != null) {
            int id = v.getId();
            switch (id) {
                case R.id.dialog_category_update_cancel:
                    categoryUpdateInterface.updateCategoryClickId(id);
                    break;
                case R.id.dialog_category_update_ensure:
                    String inputString = editDialogEdit.getText().toString().trim();
                    categoryUpdateInterface.updateCategoryEditText(inputString, position);
                    categoryUpdateInterface.updateCategoryClickId(id);
                    break;
            }
        }
    }
}
